package com.emar.spring.service;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.emar.spring.controller.UserController;
import com.emar.spring.dao.UserDao;
import com.emar.spring.model.UserEntity;

@Service
public class UserService {
	private Log log = LogFactory.getLog(UserService.class);
	@Autowired
	private UserDao userDao;
	
	public UserEntity login(String username,String password){
		UserEntity user = new UserEntity();
		user.setAccount(username);
		return userDao.getOneUser(user);
	}
	
	public List<UserEntity> getAllUserList(UserEntity user,int pageNumber,int pageSize){
		return userDao.getUserPageList(user, pageNumber, pageSize);
	}
	
	public int getCount(UserEntity user,int pageNumber,int pageSize){
		return userDao.getUserCount(user);
	}
	
	public int addUser(UserEntity user){
		int i =0;
		try {
			i = userDao.insertUser(user);
		} catch (Exception e) {
			log.error( "创建用户失败",e);
		}
		return i;
	}
	
	public int updateUser(UserEntity user){
		int i =0;
		try {
			i = userDao.updateUser(user);
		} catch (Exception e) {
			log.error( "更新用户失败",e);
		}
		return i;
	}
	
	public UserEntity getOneUser(UserEntity user){
		return userDao.getOneUser(user);
	}
}
